<?php
spl_autoload_register(function($class_name){
    $list=explode("\\",$class_name);
    if(count($list) === 1){
        $path=find_file("class",$class_name.".php");
        if($path === false) return;
        $path = __DIR__ . "/" . $path;
    }
    elseif(count($list) >= 2){
        $class_name=array_pop($list);
        $type=array_pop($list);
        $path = __DIR__ . "/$type/$class_name.php";
    }
    else{
        return;
    }
    if(file_exists($path)){
        include_once $path;
    }
});

function find_file($dir_path,$file_name)
{
    if(!is_dir($dir_path)){
        return false;
    }
    $list=scandir($dir_path);
    foreach($list as $name){
        if(in_array($name,[".",".."])) continue;
        $path=$dir_path."/".$name;
        if(is_file($path)){
            if($name === $file_name){
                return $path;
            }
        }
        elseif(is_dir($path)){
            $res=find_file($path,$file_name);
            if($res !== false){
                return $res;
            }
        }
    }
    return false;
}
